package com.yami.shop.cp.comment.model;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.yami.shop.cp.comment.dto.CollaborativePurchaseMergerDto;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Objects;

/**
 * <p>
 * 
 * </p>
 *
 * @author xch
 * @since 2021-06-28
 */
@Data
@TableName("tz_collaborative_purchase")
public class CollaborativePurchase implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 协同采购id
     */
    @TableId(type = IdType.ASSIGN_ID)
    private String id;

    /**
     * 协同采购清单名称
     */
    private String name;

    /**
     * 协同采购类型id
     */
    private String collaborativePurchaseTypeId;

    /**
     * 开始时间
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime startTime;

    /**
     * 结束时间
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime endTime;

    /**
     * 简介
     */
    private String synopsis;

    /**
     * 状态 0 待发送 1 收集中 2 已完成 3 异常
     */
    private String status;

    /**
     * 最大金额
     */
    private BigDecimal maxMoney;

    /**
     * 产品价格是否可见0可见1不可见
     */
    private String prodMoneyStatus;

    /**
     * 创建时间
     */
    private LocalDateTime createTime;

    /**
     * 修改时间
     */
    private LocalDateTime updateTime;

    /**
     * 创建用户id
     */
    private String userId;

    /**
     * 预留字段
     */
    private String reserved;

    /**
     * 预留字段1
     */
    private String reserved1;

    /**
     * 预留字段2
     */
    private String reserved2;

    /**
     * 预留字段3
     */
    private String reserved3;

    /**
     * 预留字段4
     */
    private String reserved4;


    /**
     * 获取采购单数据
     *
     * @return CollaborativePurchase
     */
    public static CollaborativePurchase getCollaborativePurchase(CollaborativePurchaseMergerDto collaborativePurchaseMergerDto) {
        CollaborativePurchase collaborativePurchase = new CollaborativePurchase();
        if (Objects.nonNull(collaborativePurchaseMergerDto.getId()) && collaborativePurchaseMergerDto.getId().trim().length() > 0){
            collaborativePurchase.setId(collaborativePurchaseMergerDto.getId());
        }
        collaborativePurchase.setUserId(collaborativePurchaseMergerDto.getUserId());
        collaborativePurchase.setCollaborativePurchaseTypeId(collaborativePurchaseMergerDto.getCollaborativePurchaseTypeId());
        collaborativePurchase.setProdMoneyStatus(collaborativePurchaseMergerDto.getProdMoneyStatus());
        collaborativePurchase.setName(collaborativePurchaseMergerDto.getName());
        collaborativePurchase.setStartTime(collaborativePurchaseMergerDto.getStartTime());
        collaborativePurchase.setEndTime(collaborativePurchaseMergerDto.getEndTime());
        collaborativePurchase.setSynopsis(collaborativePurchaseMergerDto.getSynopsis());
        collaborativePurchase.setStatus(collaborativePurchaseMergerDto.getStatus());
        collaborativePurchase.setMaxMoney(collaborativePurchaseMergerDto.getMaxMoney());
        return collaborativePurchase;
    }
}
